/**
 * 
 */
package com.hirstlogics.boxarrow.xml;

import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

/**
 * @author steve
 * This a utlity class for manipulation of xml
 */
public class Utility {

	/**
	 * @param read xmlstreamreader
	 * @param tagName -- the tag that must be next in line
	 * @return true if the tag was found
	 */
	public static boolean openTag(XMLStreamReader read, String tagName) {
		/* Skip White space */
		while (read.isWhiteSpace())
			try {
				read.next();
			} catch (XMLStreamException e) {
				System.out.println("Problem in Open Tag");
				e.printStackTrace();
			}
//			System.out.println("Tag found: "+read.getLocalName());
			return read.getEventType()==XMLStreamConstants.START_ELEMENT &&
			read.getNamespaceURI().equals(Persist.BOXARROW) &&
			read.getLocalName().equals(tagName);
	}

	public static void closeTag(XMLStreamReader read) {
		try {
			read.next();
			while (read.getEventType()!=XMLStreamConstants.END_ELEMENT) {
				read.next();
			}
		} catch (XMLStreamException e) {
			System.out.println("Problem in Close Tag");
			e.printStackTrace();
		}
	}
}


